<?php 

/**
 * @file api.php
 * The file with api
 *
 */

 
$Api = new Api();

class Api{

	/** Constructor */
	public function  __construct() {
	
		$docRoot = $_SERVER['DOCUMENT_ROOT'];
		include_once($docRoot.'/Power_Transmission/php/config/connection.php');
		include_once($docRoot.'/Power_Transmission/php/models/query.php');
		include_once($docRoot.'/Power_Transmission/php/models/get_geo_info.php');
		
		// Connect with Database
		$conn = connection();	
		
		$json =    '{"cseNum":"3","ambientTemp":"5","windSpeed":"10","windDirec":"15","relHumid":"0.00314","precipRate":"0.0","airPres":"85161","swRad":"0.0","lwRad":"293","cdrType":"3","initCdrTemp":"75","maxCdrTemp":"1000","emissivity":"0.78","solarAbs":"0.87","towerNum":"70","funcName":"getAmpacityCdrName"}';  // $_POST['jsonData'] 
		$jasonData = json_decode($json, true);	
		if($jasonData['cseNum'] == '3' )
		{
			$this->getAmpacityCdrName($jasonData);
		}		
	} 

	/** @param $jasonData a set of parameters encoded into json format 
		@param cdrType type
		@return the function returns nothing
	*/
	public function getAmpacityCdrName($jasonData)
	{
		$geoData = getGeoInfo($jasonData['towerNum']);	
		$longitude = $geoData[0]['longitude'];
		$lat = $geoData[0]['latitude'];
		$elevation = $geoData[0]['elevation'];
		$heading = $geoData[0]['heading'];
		
		// Executing IEEE standard to compute line Ampacity		
		exec("IEEE.exe ". $jasonData['cseNum']. " " .$jasonData['cdrType']." ".$jasonData['windSpeed']." ".$jasonData['windDirec']." ".$jasonData['relHumid']." ".$jasonData['precipRate']." ".$jasonData['airPres']." ".$jasonData['swRad']." ".$jasonData['lwRad']." ".$jasonData['emissivity']." ".$jasonData['solarAbs']." ".$jasonData['initCdrTemp']." ".$jasonData['maxCdrTemp']." ".$jasonData['ambientTemp']." ".$lat." ".$elevation." ".$heading , $output);	
		$temp_data = array ("amp" => $output[0]);
		echo json_encode($temp_data);
		exit;
	}
}
?>